package com.itheima.pojo;

import java.util.List;

/**
 * @author MaQing
 * @create 2022-05-14 20:39
 */
public class PageInfo <T>{
    private List<T> list;//当前页显示的数据信息
    private int currentPage;//当前页页码（上一页，下一页）
    private int pageSize;//每页显示的条数
    private int totalCount;//总条数
    private int totalPage;//总页数（计算）

    @Override
    public String toString() {
        return "PageInfo{" +
                "list=" + list +
                ", currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                '}';
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * 对页数进行计算
     * @return
     */
    public int getPageSize() {

        //总页数=总条数/每页显示条数
        //向上取整
        double page = Math.ceil(totalCount / pageSize);
        return (int)page;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public PageInfo(int pageSize, int totalCount) {
        this.pageSize = pageSize;
        this.totalCount = totalCount;
    }
}
